package com.wondersgroup.framework.widget.taglib.form;

import com.wondersgroup.framework.widget.annotations.WidgetTag;
import com.wondersgroup.framework.widget.annotations.WidgetTagAttribute;
import com.wondersgroup.framework.widget.context.DefaultSettings;
import com.wondersgroup.framework.widget.taglib.WidgetTagSupport;
import com.wondersgroup.framework.widget.validation.annotation.ValueValidate;

import java.util.ArrayList;

import javax.servlet.jsp.JspException;

import org.springframework.beans.BeanUtils;

@WidgetTag(name = "gridSelectColumn", tldTagClass = "com.wondersgroup.framework.widget.taglib.form.GridSelectColumnTag", description = "下拉表格列，渲染")
public class GridSelectColumnTag extends WidgetTagSupport {
	/**
	 * 添加固定版本号
	 */
	private static final long serialVersionUID = 1L;
	public static final String GRIDSELECT_COLUMN = "wonders.gridSelect.column";
	private String width = DefaultSettings.get("widget.gridselectcolumn.width");
	private String property;
	private String header;

	@ValueValidate({ "left", "right", "center" })
	private String align;
	private String dataType;
	private String rendererData;

	public String getWidth() {
		return this.width;
	}

	@WidgetTagAttribute(description = "下拉表格的列宽，默认为配置文件中的widget.gridselectcolumn.width值", type = "String")
	public void setWidth(String paramInt) {
		this.width = paramInt;
	}

	public String getProperty() {
		return this.property;
	}

	@WidgetTagAttribute(description = "下拉表格的列属性映射", required = true)
	public void setProperty(String paramString) {
		this.property = paramString;
	}

	public String getHeader() {
		return this.header;
	}

	@WidgetTagAttribute(description = "下拉表格的列头名称")
	public void setHeader(String paramString) {
		this.header = paramString;
	}

	public String getAlign() {
		return this.align;
	}

	@WidgetTagAttribute(description = "下拉表格的列对齐模式,限选:left,right,center")
	public void setAlign(String paramString) {
		this.align = paramString;
	}

	public String getDataType() {
		return this.dataType;
	}

	@WidgetTagAttribute(description = "下拉表格的列数据类型")
	public void setDataType(String paramString) {
		this.dataType = paramString;
	}

	public String getRendererData() {
		return this.rendererData;
	}

	@WidgetTagAttribute(description = "[可选]绑定字典，数据为javascript数据格式(例如: [['1','男'],['2','女']] )，可以是通过JavaScript返回，也可以是EL表达式。", required = false, type = "String")
	public void setRendererData(String paramString) {
		this.rendererData = paramString;
	}

	@SuppressWarnings("unchecked")
	public void processTagContent() throws JspException {
		ArrayList<GridSelectColumnTag> localArrayList = (ArrayList<GridSelectColumnTag>) this.pageContext.getAttribute("wonders.gridSelect.column");
		if (localArrayList == null){
			localArrayList = new ArrayList<GridSelectColumnTag>();
		}
		GridSelectColumnTag localGridSelectColumnTag = new GridSelectColumnTag();
		BeanUtils.copyProperties(this, localGridSelectColumnTag);
		localArrayList.add(localGridSelectColumnTag);
		this.pageContext.setAttribute("wonders.gridSelect.column", localArrayList);
	}
}
